home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / GSRC208A.ZIP / GWSIM.C < prev    next >
C/C++ Source or Header  |  1993-08-26  |  30KB  |  824 lines

  1. #include "copyleft.h"
  2.  
  3. /*
  4.     GEPASI - a simulator of metabolic pathways and other dynamical systems
  5.     Copyright (C) 1989, 1992, 1993  Pedro Mendes
  6. */
  7.  
  8. /*************************************/
  9. /*                                   */
  10. /*         GWSIM - Simulation        */
  11. /*        MS-WINDOWS front end       */
  12. /*                                   */
  13. /*          Simulation window        */
  14. /*                                   */
  15. /*           QuickC/WIN 1.0          */
  16. /*                                   */
  17. /*   (include here compilers that    */
  18. /*   compiled GWSIM successfully)    */
  19. /*                                   */
  20. /*************************************/
  21.  
  22.  
  23. /*
  24.   be sure that IOTOP.C is recompiled and that
  25.   iotop.obj from a GWTOP compilation is not
  26.   being used now. To be sure, delete iotop.obj
  27. */
  28.  
  29. #include <windows.h>
  30. #include <string.h>
  31. #include <direct.h>
  32. #include "commdlg.h"
  33. #include "toolhelp.h"
  34. #include "basic.h"                        /* basic windows function prototypes    */
  35. #include "defines.h"                    /* symbols also used in .DLG files        */
  36. #include "globals.h"                    /* gepasi's own symbols                    */
  37. #include "gwsim.h"                        /* macros, function prototypes, etc.    */
  38. #include "gep2.h"                        /* gepasi's variables                    */
  39. #include "strtbl.h"                        /* symbols for the string table            */
  40. #include "iosim.h"
  41. #include "iotop.h"
  42.  
  43. #define HELP_PARTIALKEY   0x0105
  44.  
  45. /* Struct pointed to by WM_GETMINMAXINFO lParam
  46. typedef struct tagMINMAXINFO
  47. {
  48.  POINT ptReserved;
  49.  POINT ptMaxSize;
  50.  POINT ptMaxPosition;
  51.  POINT ptMinTrackSize;
  52.  POINT ptMaxTrackSize;
  53. } MINMAXINFO;                                   */
  54.  
  55. /* global variables    */
  56. char             szString[256];            /* variable to load resource strings    */
  57. char            szHelpFile[] =
  58.                 "GEPASI.HLP";            /* help file name                        */
  59. char            szAppName[20];            /* class name for the window            */
  60. HCURSOR            hHourGlass;                /* handle for the wait cursor            */
  61. WORD            lbWidth;                /* width of largest string in list box    */
  62. HANDLE            hInst;                  /* handle to this instance of the appl.    */
  63. HWND            hWndMain;                /* handle to the main window            */
  64. HWND            hButton1;                /* handle to push button                */
  65. HWND            hButton2;                /* handle to push button                */
  66. HMENU            hMenu;                    /* handle to the menu                    */
  67. GLOBALHANDLE    hPrm;                    /* handle to memory block with prm        */
  68. GLOBALHANDLE    hOel;                    /* handle to memory block w/ oel        */
  69. GLOBALHANDLE    hScp;                    /* handle to memory block w/ scp        */
  70. double huge        *prm[MAX_STEP];            /* mirror of params                        */
  71. struct    ou huge *oel;                    /* mirror of outpel                        */
  72. struct    sp huge *scp;                    /* mirror of spar                        */
  73. double            x[MAX_MET];                /* initial concentrations                 */
  74. int             notsaved;                /* 1 if file has not been saved            */
  75. int                eqefl;                    /* for compatibility with IOTOP.C        */
  76. int                lno;                    /* number of link to edit                */
  77. int             nlks;                    /* mirror of nlinks                        */
  78. char            GepasiIni[256];            /* GEPASI's INI file with full path        */
  79. char            GnuplotExe[256];        /* name of gnuplot.exe with full path    */
  80. char            CommandLine[1024];
  81. char            FileName[256];            /* filename of sim file with full path    */
  82. char            FileTitle[13];            /* filename of sim file  w/o full path    */
  83. char            TopFile[256];            /* filename of top file with full path    */
  84. char            TopTitle[13];            /* filename of top file w/o full path    */
  85. char            DatName[256];            /* filename of dat file with full path    */
  86. char            DatTitle[13];            /* filename of dat file w/o full path    */
  87. char            LogFile[256];            /* filename of log file with full path    */
  88. FARPROC            fpCheckSimEng;            /* MakeProcInstance of callback            */
  89. char            TempFile[256];            /* filename of temporary file            */
  90. int                TimerId;                /* identifies the timer                    */
  91. int                running;                /* set when simulation engine is active    */
  92.  
  93. #pragma alloc_text( CODE0, WinMain, clear_all, WndProc, RegisterClasses, DeleteTmp, CleanUp )
  94.  
  95.  
  96. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
  97. {
  98.  /***********************************************************************/
  99.  /* HANDLE hInstance;       handle for this instance                    */
  100.  /* HANDLE hPrevInstance;   handle for possible previous instances      */
  101.  /* LPSTR  lpszCmdLine;     long pointer to exec command line           */
  102.  /* int    nCmdShow;        Show code for main window display           */
  103.  /***********************************************************************/
  104.  
  105.  MSG        msg;           /* MSG structure to store your messages        */
  106.  int        nRc;           /* return value from Register Classes          */
  107.  char       *ptr;
  108.  LPSTR        lp;
  109.  OFSTRUCT    OfStruct;
  110.  HANDLE        hAcc;
  111.  
  112.  strcpy(szAppName, "GWSIM");
  113.  hInst = hInstance;
  114.  if(!hPrevInstance)
  115.    {
  116.     /* register window classes if first instance of application         */
  117.     if ((nRc = RegisterClasses()) == -1)
  118.       {
  119.        /* registering one of the windows failed                         */
  120.        LoadString(hInst, IDS_ERR_REGISTER_CLASS, szString, sizeof(szString));
  121.        MessageBeep( MB_ICONHAND );
  122.        MessageBox(NULL, szString, NULL, MB_ICONEXCLAMATION);
  123.        return nRc;
  124.       }
  125.    }
  126.  
  127.  /* setup the device independent screen units    */
  128.  InitScrScale();
  129.  
  130.  /* load the wait cursor                                                */
  131.  hHourGlass = LoadCursor(NULL, IDC_WAIT);
  132.  
  133.  /* load the accelerators table    */
  134.  hAcc = LoadAccelerators( hInst, (LPSTR) "ACCTABLE" );
  135.  
  136.  if( InitGepasiVar() != 0 )                    /* initialize GEPASI's vars */
  137.  {
  138.   LoadString(hInst, IDS_ERR_OUT_OF_MEM, szString, sizeof(szString));
  139.   MessageBeep( MB_ICONHAND );
  140.   MessageBox(NULL, szString, NULL, MB_ICONSTOP);
  141.   if(!hPrevInstance) UnregisterClass(szAppName, hInst);
  142.   return IDS_ERR_OUT_OF_MEM;
  143.  }
  144.  
  145.  /* get the path of GEPASI's binary files directory    */
  146.  GetModuleFileName( hInst, (LPSTR) GepasiIni, sizeof( GepasiIni ) );
  147.  ptr = strrchr( GepasiIni, '\\' );
  148.  *(ptr+1) = '\0';
  149.  /* append the filename of the INI file    */
  150.  lstrcat( (LPSTR) GepasiIni, (LPSTR) "GEPASI.INI" );
  151.  
  152.  /* create application's Main window                                    */
  153.  hWndMain = CreateWindow(
  154.                 szAppName,               /* Window class name           */
  155.                 "GEPASI - Simulation",   /* Window's title              */
  156.                 WS_CAPTION      |        /* Title and Min/Max           */
  157.                 WS_SYSMENU      |        /* Add system menu box         */
  158.                 WS_MINIMIZEBOX  |        /* Add minimize box            */
  159.                 WS_CLIPCHILDREN |        /* don't draw in child windows areas */
  160.                 WS_OVERLAPPED,
  161.                 CW_USEDEFAULT, 0,        /* Use default X, Y            */
  162.                 ScrX(180), ScrY(90),
  163.                 NULL,                    /* Parent window's handle      */
  164.                 NULL,                    /* Default to Class Menu       */
  165.                 hInst,                   /* Instance of window          */
  166.                 NULL);                   /* Create struct for WM_CREATE */
  167.  
  168.  if(hWndMain == NULL)
  169.  {
  170.   LoadString(hInst, IDS_ERR_CREATE_WINDOW, szString, sizeof(szString));
  171.   MessageBeep( MB_ICONEXCLAMATION );
  172.   MessageBox(NULL, szString, NULL, MB_ICONEXCLAMATION);
  173.   TidyGepasiVar();
  174.   return IDS_ERR_CREATE_WINDOW;
  175.  }
  176.  
  177.  InitTxtMetrics( hWndMain );
  178.  
  179.  /* create the button controls */
  180.  hButton1 = CreateWindow( "Button", "&Top",
  181.                           WS_CHILD | WS_VISIBLE | WS_TABSTOP,
  182.                           ScrX(114), ScrY(40),
  183.                           ScrX(30),  ScrY(24),
  184.                           hWndMain,  IDC_BUTTON1, hInst, NULL );
  185.  if(hButton1 == NULL)
  186.  {
  187.   LoadString(hInst, IDS_ERR_CREATE_WINDOW, szString, sizeof(szString));
  188.   MessageBeep( MB_ICONHAND );
  189.   MessageBox(NULL, szString, NULL, MB_ICONSTOP);
  190.   CleanUp( hWndMain, hPrevInstance );
  191.   return IDS_ERR_CREATE_WINDOW;
  192.  }
  193.  hButton2 = CreateWindow( "Button", "&Run!",
  194.                           WS_CHILD | WS_VISIBLE | WS_TABSTOP,
  195.                           ScrX(145), ScrY(40),
  196.                           ScrX(30),  ScrY(24),
  197.                           hWndMain,  IDC_BUTTON2, hInst, NULL );
  198.  if(hButton2 == NULL)
  199.  {
  200.   LoadString(hInst, IDS_ERR_CREATE_WINDOW, szString, sizeof(szStri